<?php
class Tour extends Public_Controller {
	/// ------- validation_rule define
	public function __construct() {
		parent :: __construct();
		$this->load->helper('url');
		$this->load->library('form_validation');
		$this->load->model('tour_m');
		$this->load->library("pagination");
	}

	public function index() {
		$this->template->title("This for page title")
		/*->set_breadcrumb(lang('blog:blog_title'))
		->set_metadata('description',)
		->set_metadata('keywords', $meta['keywords'])
		->set('pagination', $pagination)*/
		
		->set('results', $this->tour_m->getAllTour($limit=null,$start=null))->build('index'); 
				
	}

	public function vtc_tour() {
		if (isset ($_GET['id'])) {

			$this->template->title("This for page title")
			->set('results', $this->tour_m->getAllById($_GET['id']))->build('vtc_tour');
		}

	}
	public function vtc_book() {
		$this->load->helper(array (
			'form',
			'url'
		));
		$this->template->title("This for page title")
		->set('results', $this->tour_m->getAllTour($limit=null,$start=null))->build('vtc_book');
	}
	public function send_book() {
		$this->load->library('email');
		/*$this->load->library('form_validation');
		$this->form_validation->set_rules('firstname', 'firstname', 'required');
		$this->form_validation->set_rules('lastname', 'lastname', 'required');
		$this->form_validation->set_rules('telephone', 'telephone', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');*/
		//echo isset ($_POST['id'])?$_POST['id']:0;
		$to='bona.chhut@gmail.com';
			if(isset($_POST['book']) && isset ($_POST['id'])){
				$title = $_POST['title'];
				$firstname = $_POST['firstname'];
				$lastname = $_POST['lastname'];
				$from= $_POST['email'];
				$telephone= $_POST['telephone'];
				$subject=$_POST['subject'];
				$message= $_POST['description'];
				
				//get value from for
				$this->email->from($from, $firstname.' '.$lastname);
				$this->email->to($to);
				//$this->email->cc('');
				//$this->email->bcc('');
				
				$this->email->subject($subject);
				$this->email->message($message);
				
				$this->email->send();
				//echo $this->email->print_debugger();
				$this->template->title("Thanks")
				->build('thank');
		}
	}
	public function phnompenh(){
		$config['base_url'] = 'http://vtc.test/tour/phnompenh';
		$config['total_rows'] = 2;
		$config['per_page'] = 2;
		$this->pagination->initialize($config); 
		$this->template->title("List hotel of Phnom Penh")
		->set('results', $this->tour_m->getAllHotelPhnomPenh())->build('index');
		
	}
	public function siemreap(){
		$this->template->title("List hotel of Siem Reap")
		->set('results', $this->tour_m->getAllHotelSiemReap())->build('index');
		
	}
	public function sihanouk(){
		$this->template->title("List hotel of Sihanouk Ville")
		->set('results', $this->tour_m->getAllHotelSihanouk())->build('index');
		
	}
	public function package(){
		$config = array();
        $config["base_url"] = base_url() . "tour/package";
        $config["total_rows"] = $this->tour_m->package_count();
        $config["per_page"] = 4;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["links"]=$this->pagination->create_links();
		$this->template->title("List Package tour")
		->set('results', $this->tour_m->getAllPackage($config["per_page"],$page))->build('package',$data);
		
	}
	public function cambodia(){
		$config = array();
        $config["base_url"] = base_url() . "tour/cambodia";
        $config["total_rows"] = $this->tour_m->campbodiaCount();
        $config["per_page"] = 4;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
       // $data["results"]=$this->tour_m->getAllCambodia($config["per_page"], $page);
        $data["links"]=$this->pagination->create_links();
        //$this->load->view("cambodia", $data);
		$this->template->title("Cambodia")
		->set('results', $this->tour_m->getAllCambodia($config["per_page"], $page))->build('cambodia',$data);
		
	}
	//--------package tour initialize----------
	public function unique(){
		$config = array();
        $config["base_url"] = base_url() . "tour/unique";
        $config["total_rows"] = $this->tour_m->package_count();
        $config["per_page"] = 1;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["links"]=$this->pagination->create_links();
        //$data['package'] = $this->tour_m->get4Packages();
		$this->template->title("Unique Touch Tour")
		->set('results', $this->tour_m->getAllPackage($config["per_page"],$page))->build('unique',$data);
		
	}
	public function angkor(){
		$this->template->title("Angkor Adventure")
		->build('angkor');
	}
	//---------tab in hotel page menu----------//
	public function hotel(){
		$this->template->title("List hotel of Phnom Penh")
		->build('hotel');
		
	}
}